import React from 'react';
import { useWindowSize } from 'react-use';

const checkPlatform = () =>
    navigator.userAgent.match(/(iPhone|iPod|Android|ios|iOS|iPad|Backerry|WebOS|Symbian|Windows Phone|Phone)/i);

const usePlatform = () => {
    const { width } = useWindowSize();
    const [isMobile, setIsMobile] = React.useState(width <= 750 || !!checkPlatform());

    React.useEffect(() => {
        setIsMobile(width <= 750 || !!checkPlatform());
    }, [width]);

    return { isMobile };
};

export default usePlatform;
